# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=gtksourceview
pkgbase=mingw-w64-${_realname}4
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}4"
pkgver=4.6.0
pkgrel=1
pkgdesc="A text widget adding syntax highlighting and more to GNOME (mingw-w64)"
arch=('any')
url="https://www.gnome.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
source=("https://download.gnome.org/sources/gtksourceview/${pkgver%.*}/gtksourceview-${pkgver}.tar.xz"
        "skip-tests.patch")
sha256sums=('4c13e30ab2e602abdc56f55d35f43c1142a79b1cd77aa8839d2fc85e966d9a85'
            '61da80db865434f5c7fbdf79e2dc38eeaaad4eca52313e9eac0b24f3fdfd0ffe')

prepare() {
  cd ${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}"/skip-tests.patch
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  meson \
    --buildtype=plain \
    -Dgtk_doc=true \
    "../${_realname}-${pkgver}"

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|${_PRE_WIN}|${MINGW_PREFIX}|g" -i "${pcfile}"
  done

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}4/COPYING"
}
